﻿using Common.Data;
using Common.Tools;
using CoreApi.Meta;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Transactions;

namespace CoreApi.Impl
{
    public class UserService:IUserService
    {

        private string _conName = "user";

        public UserService()
        {
            this._conName = ConfigurationManager.AppSettings["user.connectionStringName"] ?? _conName;
        }

        private bool CheckMemberByRegMobile(Database db, DbTransaction trans, string registerMobile)
        {
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("a.RegMobile",registerMobile)
            };
            int cnt = DbHelper.ExecuteScalar(db, trans, SQL.UserService.MemberRegisterMobile, filters);
            return cnt > 0;
        }
        private IDictionary HasSameFamilyMember(Database db, DbTransaction trans, string realName,string registerMobile)
        {
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("RealName",realName)
                ,new DbFilter("RegMobile",registerMobile)
            };
            return DbHelper.ExecuteSingle(db, trans, SQL.TABLE.MEMBER, "MemberId".BuildDbColumnArray(), filters);
        }
        public ReturnValue CheckRegisterMobile(string registerMobile)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            bool regM = CheckMemberByRegMobile(db, null, registerMobile);
            if (regM) return new ReturnValue();
            else return new ReturnValue(false,ErrorMessage.UserService.MemberNotFound);
        }
        public ReturnValue BindWechat(string registerMobile, string wechatUnionId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("RegMobile",registerMobile)
                ,new DbFilter("WechatUnionId",string.Empty)
            };
            DbColumn[] columns = new DbColumn[]{
                new DbColumn("WechatUnionId",wechatUnionId)
                ,new DbColumn("BindTime",DbType.DateTime,DateTime.Now)
            };
            int cnt = DbHelper.ExecuteUpdate(db, null, SQL.TABLE.MEMBER, columns, filters);
            if (cnt <= 0) return new ReturnValue(false, ErrorMessage.UserService.BindWechatFailed);
            else return new ReturnValue();
        }
        public ReturnValue AccountList(string wechatUnionId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("a.WechatUnionId",wechatUnionId)
            };
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.UserService.AccountList, filters);
            return new ReturnValue(dt);
        }
        public ReturnValue AccountAlarmList(string weichatUnionId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            DbFilter[] filters = new DbFilter[]{
              new DbFilter("a.Status",AlarmStatus.Open) 
              ,new DbFilter("c.WechatUnionId",weichatUnionId)
            };
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.UserService.AlarmList, filters, "a.AlarmTime desc");
            return new ReturnValue(dt);
        }
        public ReturnValue ServiceSheetList(string weichatUnionId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            DbFilter[] filters = new DbFilter[]{
              new DbFilter("a.Status",AlarmStatus.Open) 
              ,new DbFilter("e.WechatUnionId",weichatUnionId)
            };
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.UserService.SheetList, filters, "a.CreateTime desc");
            return new ReturnValue(dt);
        }
        public ReturnValue DeviceBrandList()
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.TABLE.BRAND, "BrandId,Name".BuildDbColumnArray(), new DbFilter[] { });
            return new ReturnValue(dt);
        }
        public ReturnValue DeviceModelList(string brandId, string deviceType)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.TABLE.MODEL, "ModelId,DeviceType,Model,DataNumber01,DataNumber02,DataNumber03,DataNumber04".BuildDbColumnArray(), new DbFilter[] { new DbFilter("BrandId", brandId),new DbFilter("DeviceType",deviceType) });
            return new ReturnValue(dt);
        }

        private ReturnValue CheckUnionId(Database db, DbTransaction trans,string wechatUnionId, string accountId)
        {
            DbFilter[] filters=new DbFilter[]{
                new DbFilter("a.WechatUnionId",wechatUnionId)
                ,new DbFilter("b.AccountId",accountId)
            };
            IDictionary dict = DbHelper.ExecuteSingle(db, trans, SQL.UserService.CheckUnionId, filters);
            if (dict == null) return new ReturnValue(false, ErrorMessage.UserService.MemberNotFound);
            if (dict["CANMANAGEMENT"].Equals(BOOL.True)) return new ReturnValue(true, dict);
            else return new ReturnValue(false, ErrorMessage.UserService.CantManagement);
        }
        private ReturnValue CheckUnionIdByCitizen(Database db, DbTransaction trans, string wechatUnionId, string citizenId)
        {
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("a.WechatUnionId",wechatUnionId)
                ,new DbFilter("c.CitizenId",citizenId)
            };
            IDictionary dict = DbHelper.ExecuteSingle(db, trans, SQL.UserService.CheckUnionIdByCitizen, filters);
            if (dict == null) return new ReturnValue(false, ErrorMessage.UserService.CitizenNotFound);
            if (dict["CANMANAGEMENT"].Equals(BOOL.True)) return new ReturnValue(true, dict);
            else return new ReturnValue(false, ErrorMessage.UserService.CantManagement);
        }
        private ReturnValue CheckUnionIdByMember(Database db, DbTransaction trans, string wechatUnionId, string memberId)
        {
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("a.WechatUnionId",wechatUnionId)
                ,new DbFilter("c.MemberId",memberId)
            };
            IDictionary dict = DbHelper.ExecuteSingle(db, trans, SQL.UserService.CheckUnionIdByMember, filters);
            if (dict == null) return new ReturnValue(false, ErrorMessage.UserService.MemberNotFound);
            if (dict["CANMANAGEMENT"].Equals(BOOL.True)) return new ReturnValue(true, dict);
            else return new ReturnValue(false, ErrorMessage.UserService.CantManagement);
        }
        private ReturnValue CheckUnionIdByDevice(Database db, DbTransaction trans, string wechatUnionId, string deviceId)
        {
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("a.WechatUnionId",wechatUnionId)
                ,new DbFilter("c.DeviceId",deviceId)
            };
            IDictionary dict = DbHelper.ExecuteSingle(db, trans, SQL.UserService.CheckUnionIdByDevice, filters);
            if (dict == null) return new ReturnValue(false, ErrorMessage.UserService.DeviceNotFound);
            if (dict["CANMANAGEMENT"].Equals(BOOL.True)) return new ReturnValue(true, dict);
            else return new ReturnValue(false, ErrorMessage.UserService.CantManagement);
        }

        #region Senior Citizen
        public ReturnValue SenionCitizenList(string wechatUnionId, string accountId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("c.WechatUnionId",wechatUnionId)
                ,new DbFilter("a.AccountId",accountId)
            };
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.UserService.SeniorCitizenList, filters);
            return new ReturnValue(dt);
        }
        public ReturnValue AddSeniorCitizen(string wechatUnionId, string accountId, string name, string gender, int birthdayYear, string contactMobile,string IdCard, int height, int weight, string nativePlace)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionId(db, null, wechatUnionId, accountId);
            if (!rv1.Passed) return rv1;                      
            string citizenId = IdHelper.GetGuid();
            DbColumn[] columns = new DbColumn[]{
                new DbColumn("CitizenId",citizenId)
                ,new DbColumn("AccountId",accountId)
                ,new DbColumn("Name",name)
                ,new DbColumn("Gender",gender)
                ,new DbColumn("BirthdayYear",DbType.Int32,birthdayYear)
                ,new DbColumn("contactMobile",contactMobile)
                ,new DbColumn("IdCard",IdCard)
                ,new DbColumn("Height",DbType.Int32,height)
                ,new DbColumn("Weight",DbType.Int32,weight)
                ,new DbColumn("NativePlace",nativePlace)
            };
            int ret=DbHelper.ExecuteInsert(db, null, SQL.TABLE.CITIZEN, columns);
            if (ret > 0) return new ReturnValue(true, citizenId);
            else return new ReturnValue(false, ErrorMessage.UserService.AddSeniorCitizenFailed);
        }
        public ReturnValue UpdateSeniorCitizen(string wechatUnionId, string citizenId, string name, string gender, int birthdayYear, string contactMobile,string IdCard, int height, int weight, string nativePlace)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionIdByCitizen(db, null, wechatUnionId, citizenId);
            if (!rv1.Passed) return rv1;       
            DbColumn[] columns = new DbColumn[]{
                new DbColumn("Name",name)
                ,new DbColumn("Gender",gender)
                ,new DbColumn("BirthdayYear",DbType.Int32,birthdayYear)
                ,new DbColumn("contactMobile",contactMobile)
                ,new DbColumn("IdCard",IdCard)
                ,new DbColumn("Height",DbType.Int32,height)
                ,new DbColumn("Weight",DbType.Int32,weight)
                ,new DbColumn("NativePlace",nativePlace)
            };
            DbFilter[] filters = new DbFilter[]
            {
                new DbFilter("CitizenId",citizenId)
            };
            int ret = DbHelper.ExecuteUpdate(db, null, SQL.TABLE.CITIZEN, columns,filters);
            if (ret > 0) return new ReturnValue(true, citizenId);
            else return new ReturnValue(false, ErrorMessage.UserService.UpdateSeniorCitizenFailed);
        }
        public ReturnValue RemoveSeniorCitizen(string wechatUnionId, string citizenId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionIdByCitizen(db, null, wechatUnionId, citizenId);
            if (!rv1.Passed) return rv1;
            DbFilter[] filters = new DbFilter[]
            {
                new DbFilter("CitizenId",citizenId)
            };
            using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
            {
                int ret = DbHelper.ExecuteDelete(db, null, SQL.TABLE.CITIZEN, filters);
                int ret2 = DbHelper.ExecuteDelete(db, null, SQL.TABLE.DEVICEDATA, filters);
                tx.Complete();
            }
            return new ReturnValue(true, citizenId);
        }
        #endregion

        #region Device
        public ReturnValue DeviceList(string wechatUnionId, string accountId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("d.WechatUnionId",wechatUnionId)
                ,new DbFilter("a.AccountId",accountId)
            };
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.UserService.DeviceList, filters);
            return new ReturnValue(dt);
        }
        public ReturnValue AddDevice(string wechatUnionId, string accountId, string brandId, string deviceType, string model, string deviceSN,string simSN)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionId(db, null, wechatUnionId, accountId);
            if (!rv1.Passed) return rv1;
            string deviceId = IdHelper.GetGuid();
            DbColumn[] columns = new DbColumn[]
            {
                new DbColumn("DeviceId",deviceId)
                ,new DbColumn("AccountId",accountId)
                ,new DbColumn("BrandId",brandId)
                ,new DbColumn("Model",model)
                ,new DbColumn("DeviceType",deviceType)
                ,new DbColumn("DeviceSN",deviceSN)
                ,new DbColumn("SIMSN",simSN)
            };
            using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
            {
                int ret=DbHelper.ExecuteInsert(db,null,SQL.TABLE.DEVICE,columns);
                tx.Complete();
                if (ret==0) return new ReturnValue(false,ErrorMessage.UserService.CreateDeviceFailed);
                return new ReturnValue(true, deviceId);
            }
        }
        public ReturnValue BindDeviceData(string wechatUnionId,string deviceId, string dataNumber, string accountId,string citizenId="")
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv0 = CheckUnionIdByDevice(db, null, wechatUnionId, deviceId);
            if (!rv0.Passed) return rv0;
            ReturnValue rv1 = CheckUnionId(db, null, wechatUnionId, accountId);
            if (!rv1.Passed) return rv1;
            if (citizenId != null && !citizenId.Equals(""))
            {
                ReturnValue rv2 = CheckUnionIdByCitizen(db, null, wechatUnionId, citizenId);
                if (!rv2.Passed) return rv2;
            }
            DbColumn[] columns = new DbColumn[]{
                new DbColumn("DeviceId",deviceId)
                ,new DbColumn("DataNumber",dataNumber)
                ,new DbColumn("AccountId",accountId)
                ,new DbColumn("CitizenId",citizenId)
            };
            DbColumn[] columns0 = new DbColumn[]{
                new DbColumn("AccountId",accountId)
                ,new DbColumn("CitizenId",citizenId)
            };
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("DeviceId",deviceId)
                ,new DbFilter("DataNumber",dataNumber)
            };
            using (TransactionScope tx = new TransactionScope())
            {
                int ret = DbHelper.ExecuteUpdate(db, null, SQL.TABLE.DEVICEDATA, columns0, filters);
                if (ret==0) DbHelper.ExecuteInsert(db, null, SQL.TABLE.DEVICEDATA, columns);
                tx.Complete();
            }
            return new ReturnValue();
        }
        public ReturnValue GetDeviceData(string wechatUnionId, string deviceId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionIdByDevice(db, null, wechatUnionId, deviceId);
            if (!rv1.Passed) return rv1;
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.UserService.DeviceDataList,new DbFilter[]{ new DbFilter("a.DeviceId",deviceId) });
            return new ReturnValue(dt);
        }
        public ReturnValue RemoveDevice(string wechatUnionId, string deviceId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionIdByDevice(db, null, wechatUnionId, deviceId);
            if (!rv1.Passed) return rv1;
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("DeviceId",deviceId)
            };
            using(TransactionScope tx=new TransactionScope(TransactionScopeOption.Required))
            {
                DbHelper.ExecuteDelete(db, null, SQL.TABLE.DEVICEDATA, filters);
                DbHelper.ExecuteDelete(db, null, SQL.TABLE.DEVICE, filters);
                tx.Complete();
                return new ReturnValue(true, deviceId);
            }
        }
        #endregion

        #region Situation
        public ReturnValue BloodPressureSituation(string wechatUnionId, string citizenId, string timeRange)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1=CheckUnionIdByCitizen(db,null,wechatUnionId,citizenId);
            if (!rv1.Passed) return rv1;
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("a.MeasureTime",DbType.DateTime,timeRange.Split(';'))
                ,new DbFilter("d.WechatUnionId",wechatUnionId)
                ,new DbFilter("b.CitizenId",citizenId)
            };
            DataTable dt=DbHelper.ExecuteDataTable(db, null, SQL.UserService.BPSituation, filters, "a.MeasureTime");
            return new ReturnValue(dt);
        }
        public ReturnValue GlycemicSituation(string wechatUnionId, string citizenId, string timeRange)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionIdByCitizen(db, null, wechatUnionId, citizenId);
            if (!rv1.Passed) return rv1;
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("a.MeasureTime",DbType.DateTime,timeRange.Split(';'))
                ,new DbFilter("d.WechatUnionId",wechatUnionId)
                ,new DbFilter("b.CitizenId",citizenId)
            };
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.UserService.GLSituation, filters, "a.MeasureTime");
            return new ReturnValue(dt);
        }
        public ReturnValue SmokeAlarmSituation(string wechatUnionId, string accountId, string timeRange)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionId(db, null, wechatUnionId, accountId);
            if (!rv1.Passed) return rv1;
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("a.MeasureTime",DbType.DateTime,timeRange.Split(';'))
            };
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.UserService.SASituation, filters, "a.MeasureTime");
            return new ReturnValue(dt);
        }
        #endregion

        #region Family Member 
        public ReturnValue FamilyMemberList(string wechatUnionId, string accountId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("d.WechatUnionId",wechatUnionId)
                ,new DbFilter("c.AccountId",accountId)
            };
            DataTable dt = DbHelper.ExecuteDataTable(db, null, SQL.UserService.FamilyMemberList, filters);
            return new ReturnValue(dt);
        }
        public ReturnValue AddFamilyMember(string wechatUnionId, string accountId, string realName, string regMobile, string otherPhone, string province, string city, string district, string address, string postcode, string canManagement = "False",string liveTogether="False")
        {
            if (accountId == null || accountId.Length < 1 || realName == null || realName.Length < 1 || regMobile == null || regMobile.Length < 1) return new ReturnValue(false, ErrorMessage.UserService.MissingData);
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionId(db, null, wechatUnionId, accountId);
            if (!rv1.Passed) return rv1;
            string memberId = IdHelper.GetGuid();
            DbColumn[] columns = new DbColumn[]{
                new DbColumn("MemberId",memberId)
                ,new DbColumn("RealName",realName)
                ,new DbColumn("RegMobile",regMobile)
                ,new DbColumn("OtherPhone",otherPhone)
                ,new DbColumn("Province",province)
                ,new DbColumn("City",city)
                ,new DbColumn("District",district)
                ,new DbColumn("Address",address)
                ,new DbColumn("PostCode",postcode)
                ,new DbColumn("CreateBy",(rv1.Data as IDictionary)["REALNAME"].ToString())
                ,new DbColumn("CreateTime",DbType.DateTime,DateTime.Now)
            };
            DbColumn[] columns2 = new DbColumn[]{
                new DbColumn("MemberId",memberId)
                ,new DbColumn("AccountId",accountId)
                ,new DbColumn("CanManagement",canManagement)
                ,new DbColumn("LiveTogether", liveTogether)
                ,new DbColumn("CreateBy",(rv1.Data as IDictionary)["REALNAME"].ToString())
                ,new DbColumn("CreateTime",DbType.DateTime,DateTime.Now)
            };
            using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
            {
                IDictionary old = HasSameFamilyMember(db, null, realName, regMobile);
                if (old == null && CheckMemberByRegMobile(db, null, regMobile)) return new ReturnValue(false, ErrorMessage.UserService.RegisterMobileUsed);
                if (old == null)
                {
                    int ret = DbHelper.ExecuteInsert(db, null, SQL.TABLE.MEMBER, columns);
                    if (ret <= 0) return new ReturnValue(false, ErrorMessage.UserService.CreateMemberFailed);
                }
                else columns2[0].Value = old["MEMBERID"].ToString();
                int ret2 = DbHelper.ExecuteInsert(db, null, SQL.TABLE.ACCOUNTMEMBER, columns2);
                if (ret2 <= 0) return new ReturnValue(false, ErrorMessage.UserService.CreateMemberFailed);
                tx.Complete();
                return new ReturnValue(true, memberId);
            }
        }
        public ReturnValue RemoveFamilyMember(string wechatUnionId, string memberId)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionIdByMember(db, null, wechatUnionId, memberId);
            if (!rv1.Passed) return rv1;
            IDictionary dt=rv1.Data as IDictionary;
            string accountId=dt["ACCOUNTID"].ToString();
            DbFilter[] filters=new DbFilter[]{
                new DbFilter("AccountId",accountId)    
                ,new DbFilter("MemberId",memberId)
            };
            int ret=DbHelper.ExecuteDelete(db, null, SQL.TABLE.ACCOUNTMEMBER, filters);
            return new ReturnValue(true, memberId);
        }
        public ReturnValue UpdateFamilyMember(string wechatUnionId, string memberId, string realName, string otherPhone, string province, string city,string district, string address, string postcode, string canManagement = "False", string liveTogether="False")
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionIdByMember(db, null, wechatUnionId, memberId);
            if (!rv1.Passed) return rv1;
            DbColumn[] columns = new DbColumn[]{
                new DbColumn("RealName",realName)                
                ,new DbColumn("OtherPhone",otherPhone)
                ,new DbColumn("Province",province)
                ,new DbColumn("City",city)
                ,new DbColumn("District",district)
                ,new DbColumn("Address",address)
                ,new DbColumn("PostCode",postcode)
            };
            DbFilter[] filters = new DbFilter[]{                
                new DbFilter("MemberId",memberId)
            };
            DbColumn[] columns2 = new DbColumn[]{
                new DbColumn("CanManagement",canManagement)
                ,new DbColumn("LiveTogether",liveTogether)
            };
            DbFilter[] filters2 = new DbFilter[]{
                new DbFilter("MemberId",memberId)
                ,new DbFilter("AccountId",(rv1.Data as IDictionary)["ACCOUNTID"].ToString())
            };
            using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
            {
                int ret = DbHelper.ExecuteUpdate(db, null, SQL.TABLE.MEMBER, columns, filters);
                int ret2 = DbHelper.ExecuteUpdate(db, null, SQL.TABLE.ACCOUNTMEMBER, columns2, filters2);
                tx.Complete();
                if (ret < 0 || ret2 < 0) return new ReturnValue(false, ErrorMessage.UserService.UpdateMemberFailed);
                return new ReturnValue(true, memberId);
            }
        }
        public ReturnValue ChangeFamilyMemberRegisterMobile(string wechatUnionId, string memberId, string regMobile)
        {
            Database db = DatabaseFactory.CreateDatabase(this._conName);
            ReturnValue rv1 = CheckUnionIdByMember(db, null, wechatUnionId, memberId);
            if (!rv1.Passed) return rv1;
            DbColumn[] columns = new DbColumn[]{
                new DbColumn("RegMobile",regMobile)
            };
            DbFilter[] filters = new DbFilter[]{
                new DbFilter("MemberId",memberId)
            };
            using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
            {
                if (CheckMemberByRegMobile(db, null, regMobile)) return new ReturnValue(false, ErrorMessage.UserService.RegisterMobileUsed);
                int ret = DbHelper.ExecuteUpdate(db, null, SQL.TABLE.MEMBER, columns, filters);
                tx.Complete();
                if (ret == 0) return new ReturnValue(false, ErrorMessage.UserService.ChangeMemberRegMobileFailed);
                return new ReturnValue(true, memberId);
            }
        }
        #endregion

    }
}
